//  - main处理函数
const path = require('path'),
      func = require('./common.js');
exports.main = (req,res) =>{
    const tool = require(req.bind.dir+'/module/emma.js');
    var HTML = tool.require('html');
    var h = new HTML();
    h.isMobile(req,tool);
    h.load({'title':'PATH || '+Math.random()*100000});
    //req.setEncoding('utf8');
    h.appHead('<meta charset="utf-8">'+sytle());
    var html = '<h4>Node路径包</h4>';
    html += func.navlist(func.udata(req.url,'app'));
    html += printPath();
    h.appBody(html);
    res.write(h.getHtml());
    //  清除函数缓存
    func.clear(__dirname+'/common.js');
}
function printPath(){
    var xhtml = '<div class="printPath">';
    var env = '',
        envd = process.env.PATH.split(path.delimiter);
    env = envd.join('<br>');
    xhtml += `
        <p>__dirname：${__dirname}<span class="delimiter"></span></p>
        <p>__filename：${__filename}</p>
        <p>path.extname(__filename)：${path.extname(__filename)}<span class="delimiter"></span><span class="remark">注：获取文件的后缀名！</span></p>
        <p>path.basename(__filename)：${path.basename(__filename)}</p>
        <p>path.basename(__dirname)：${path.basename(__dirname)}</p>
        <p>path.dirname(__filename)：${path.dirname(__filename)}</p>
        <p>path.dirname('D:/Joshua/Harbin@160508-160730/')= ${path.dirname('D:/Joshua/Harbin@160508-160730/')}</p>
        <p>path.delimiter= ${path.delimiter}</p>
        <p>path.format({dir: '/home/user/dir',base: 'file.txt'}):  ${path.format({dir: '/home/user/dir',base: 'file.js'})}</p>
        <p>path.join('/foo', 'bar', 'baz/asdf', 'quux', '..'):  ${path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')}</p>
        <p>process.env.PATH: <span class="delimiter"></span><span class="remark">环境变量：</span><br><span class="envString">${process.env.PATH}</span></p>
        <p>process.env.PATH.split(path.delimiter): <span class="delimiter"></span><span class="remark">环境变量：process为全局变量</span><div class="envlist">${env}</div></p>
    `;
    xhtml += '</div>';
    return xhtml;
}
function sytle(){
    var css = '<style>';
    css += `
        .printPath p{margin:0px;padding:0px;}
        body{background:black;color:white;}
        span.delimiter{margin:100px;}
        span.remark{font-size:0.84em;color:blue;}
        /*环境变量字符串*/
        span.envString{font-size:0.62em;color:yellow;}
        /*环境变量清单*/
        div.envlist{font-size:0.81em;color:green;margin:0 0 0 50px;}
    `;
    css += '</style>';
    return css;
}
